<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<p>1</p>
<p>2</p>
<p>3</p>
<script>
  /* 直接用【Symbol.iterator】的方法：*/
    function each(data) {
        if (data[Symbol.iterator]) {
            let iterator = data[Symbol.iterator]();
            let item = {
                done: false
            };
            while (!item.done) {
                item = iterator.next();
                console.log(item.value);
            }
        }
    }
    /* 使用语法糖 for of的方法： */
    function each2(data) {
        for (let item of data) {
                console.log(item)
            }
    }

    let arr = [1, 2, 3];
    let pDoms = document.getElementsByTagName('p');
    let map1 = new Map();
    map1.set('a','1');
    map1.set('b','2');

    each2(arr);
    each2(pDoms);
    each2(map1);


</script>
</body>
</html>
